package com.crayon.account.loader;

import android.content.Context;
import android.support.v4.content.AsyncTaskLoader;

import com.crayon.account.dao.DAOFood;
import com.crayon.account.dao.DAOTable;
import com.crayon.account.dao.DataBaseManager;
import com.crayon.util.GDB;
import com.google.gson.Gson;
import com.j256.ormlite.dao.Dao;

import java.util.List;

public class LoaderSQLFoodReOrder extends AsyncTaskLoader<List<DAOFood>> {


    List<DAOFood> tables;

    public LoaderSQLFoodReOrder(Context context, List<DAOFood> tables) {
        super(context);
        this.tables = tables;
    }

    @Override
	public List<DAOFood> loadInBackground() {

		DataBaseManager baseManager =DataBaseManager.getHelper(getContext());
       if(this.tables!=null && this.tables.size()>0){
            try {
                Dao<DAOFood, Integer> tbFood =baseManager.getDAOFood();
                tbFood.delete(tables);
                for(DAOFood item : tables){
                    tbFood.create(item);
                }
            }catch(Exception e ){
                GDB.log(getClass(), "result  err " + e.getMessage());
            }
            this.tables=null;
        }
		return null;
	}


}


